/**
 * 实现播放按钮
 * 创建者：Carburn Ashroom
 * 2024.2.29
 */

#include "button.h"

namespace Butt {

    void Button::draw(QPixmap* dest) const
    {
        QPainter pa {dest};
        pa.setBrush(bgc);
        pa.setPen(btn_clr.imag());
        pa.drawEllipse(pos, radius, radius);
        QRect t_rect {pos-QPoint{radius,radius},QSize{radius*2,radius*2}};
        QString text {time.running() ? btn_ch.imag() : btn_ch.real()};
        pa.setFont(time.running() ? btn_font.imag() : btn_font.real());
        pa.drawText(t_rect, Qt::AlignCenter, text);
    }

    void Button::click(QPointF p)
    {
        auto dist2 = pow(p.x()-pos.x(), 2)+pow(p.y()-pos.y(), 2);
        if (sqrt(dist2) < radius)
            time.start();
    }

}
